/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view.layer;

import java.awt.Color;
import java.awt.Graphics;

import soccerscope.model.ClientScene;
import soccerscope.util.geom.Point2f;
import soccerscope.util.geom.Tuple2f;
import soccerscope.view.FieldPane;

public class StaminaLayer extends Layer {

	public StaminaLayer(FieldPane fieldPane, boolean enable) {
		super(fieldPane, enable);
	}

	@Override
	public String getLayerName() {
		return "Stamina";
	}

	private Point2f drawPoint = new Point2f();

	private Tuple2f size = new Tuple2f();

	private Point2f drawOffset = new Point2f();

	@Override
	public void draw(Graphics g) {
		if (!this.enable)
			return;

		ClientScene clientScene = this.fieldPane.getScene();
		float playerMagnify = this.fieldPane.getPlayerMagnify();
		for (int i = 0; i < MAX_PLAYER * 2; i++) {
			if (!clientScene.player[i].isEnable())
				continue;

			float playerR = clientScene.player[i].getSize() * playerMagnify;

			// draw stamina
			g.setColor(Color.black);
			this.size.set(playerR / 2, playerR * 2);
			this.drawOffset.set(playerR + this.size.x, playerR - this.size.y);
			this.drawPoint.add(clientScene.player[i].pos, this.drawOffset);
			fillRect(g, this.drawPoint, this.size);

			if (clientScene.player[i].stamina > STAMINA_MAX * EFFORT_INC_THR)
				g.setColor(Color.green);
			else if (clientScene.player[i].stamina > STAMINA_MAX
					* EFFORT_DEC_THR)
				g
						.setColor(Color
								.getHSBColor(
										(clientScene.player[i].stamina - STAMINA_MAX
												* EFFORT_DEC_THR)
												/ (3 * (STAMINA_MAX * (EFFORT_INC_THR - EFFORT_DEC_THR))),
										1.0f, 1.0f));
			else
				g.setColor(Color.red);

			this.size.set(playerR / 2, playerR * 2
					* (clientScene.player[i].stamina / STAMINA_MAX));
			this.drawOffset.set(playerR + this.size.x, playerR - this.size.y);
			this.drawPoint.add(clientScene.player[i].pos, this.drawOffset);
			fillRect(g, this.drawPoint, this.size);
		}
	}
}
